<?php
namespace app\mp\controller;
use think\Db;

class Api extends Base {

    public function index() {
        $corpid = 'ww5aef44e0d547824f';
        $corpsecret = 'bCOxeCJxKW5qCcY8qTobYcgDK5874VlwWgZAuy5lDZE';
//        $res = curl_get_data('https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid='.$corpid.'&corpsecret='.$corpsecret);
//        $data = json_decode($res,true);
//        if(!$data) {
//            $this->log('api/index',$data,'mp.log');
//        }
//        if($data['errcode'] !== 0) {
//            $this->log('api/index',var_export($data,true),'mp.log');
//        }
//        $access_token = $data['access_token'];

//        halt($access_token);
    }
    public function test() {
        $post = input('post.');
        $code = $post['code'] ?? '';
        $access_token = "yixDbYnnuZ75ukeYuLNBFYooCavv6X0s3cFC_KMq843UF4WKE_-VE7lb--wvN6ccB0aywKh-eiWbkshPCOOFl-alX5BsidVm69hTQxEz6Q5jhjB5_aSug3TZPS3cYyfG5yHOsiQ6WY4ny-zzMA_moqEZ7KUoWmrrWNQBZiwgg0kG2BGLsieAzoRA65D4z3k6m0rHihxtreTT5rSJywkS9A";
        if(!$code) {
            return ajax('',-1,'code 不能为空');
        }
        $res = curl_get_data('https://qyapi.weixin.qq.com/cgi-bin/miniprogram/jscode2session?access_token='.$access_token.'&js_code='.$code.'&grant_type=authorization_code');

        $corpid = 'ww5aef44e0d547824f';
        $corpsecret = 'bCOxeCJxKW5qCcY8qTobYcgDK5874VlwWgZAuy5lDZE';
        $session_key = "e+DYoPlgkJzWAZVlD7nyYw==";
        $userid = "JiangHaiRui";

        return ajax($res);
    }

}